import { createSlice } from "@reduxjs/toolkit";
import dayjs from "dayjs";

export const CitySlice = createSlice({
  name: "counter",
  initialState: {
    start: "北京",
    end: "广州",
    date: dayjs().format("YYYY-MM-DD"),
  },
  reducers: {
    editcity(state, { payload }) {
      state[payload.type] = payload.city;
    },
    editdate(state, { payload }) {
      state.date = payload.date;
    },
    excity(state) {
      const temp = state.start;
      state.start = state.end;
      state.end = temp;
    },
  },
});

// Action creators are generated for each case reducer function
export const { editcity, editdate, excity } = CitySlice.actions;

export default CitySlice.reducer;
